/*Data
1.年月日 year month day
2.无参构造 初始 2010.06.17
3.带参构造
4.display() 输出
5.重载<< 输出
main
1.定义d1 d2 d3  无参 带参
2.display cout<< 输出  格式输出
3.- ++ --unsigned i
*/

#include <iostream>
using namespace std;
#include <iomanip>
#include <cmath>

class Data
{
private:
    int year;
    int month;
    int day;
public:
    Data();
    Data(int year,int month,int day);
    Data(const Data &a);
    ~Data();
    int getY();
    int getM();
    int getD();
    void display()const;
    int leap ()const;
    Data operator -(Data a);
    Data operator ++(int);
    Data operator --(int);
};
//无参构造
Data::Data()
{
    this->year = 2010;
    this->month = 6;
    this->day = 17;
}
//带参构造
Data::Data(int year,int month,int day)
:year(year),month(month),day(day){}
//拷贝构造
Data::Data(const Data & a)
{
}
//析构
Data::~Data()
{
}
//year
int Data::getY()
{
    return this->year;
}
//month
int Data::getM()
{
    return this->month;
}
//day
int Data::getD()
{
    return this->day;
}
//输出
void Data::display()const
{
    cout<< setw(4) << setfill('0') << this->year<<"/";
    cout<< setw(2) << setfill('0') << this->month<<"/";
    cout<< setw(2) << setfill('0') << this->day<<endl;
}
//<<
ostream & operator<<(ostream &out, Data & a)
{
    cout<< setw(4) << setfill('0') << a.getY()<<"/";
    cout<< setw(2) << setfill('0') << a.getM()<<"/";
    cout<< setw(2) << setfill('0') << a.getD();
    return out;
}
//1.闰年 0.非闰年
int Data::leap()const
{
    if(((this->year % 4 == 0)&&(this->year % 100 != 0)) || (this->year % 400 == 0))
    {
        return 1;
    }
    else
    {
        return 0;
    } 
}
//-
Data Data::operator - (Data a)
{

}
//++
Data Data::operator++(int)
{
    Data tmp = *this;
    if(this->leap() == 1 && this->month==2)
    {//闰年February
        if(this->day == 29)
        {//29
            this->month++;
            this->day =1;
        }
        else
        {
            this->day++;
        }
    }
    else if(this->month==2)
    {//非闰年February
        if(this->day == 28)
        {//29
            this->month++;
            this->day =1;
        }
        else
        {
            this->day++;
        }
    } 
    else if(this->month==4 ||this->month==6 ||this->month==9 ||this->month==11)
    {//litter month
        if(this->day == 30)
        {//30
            this->month++;
            this->day =1;
        }
        else
        {
            this->day++;
        }
    }
    else
    {
        if(this->month != 12)
        {//!=12
            if(this->day == 31)
            {//31
                this->month++;
                this->day =1;
            }
            else
            {
                this->day++;
            }
        }
        else
        {
            if(this->day == 31)
            {//beyond the year
                this->year ++;
                this->month =1;
                this->day =1;
            }
            else
            {
                this->day++;
            }
        }
    }
    return tmp;
}
 int main(int argc,char*argv[])
 {
    Data day1;
    Data day2(2008,2,29);
    day1.display();
    day2.display();

    day1++;
    day2++;
    cout<<day1<<endl;
    cout<<day2<<endl;

    int a=-1;
    int b=abs(a);
    cout<<b<<endl;

     return 0;
 }